
import { DomainName } from '../config/index.js'
import httpBefore from './httpBefore.js'

function http(url, config) {
  let {
    data = {},
    contentType = "application/json",
    method = "GET",
  } = { ...config };
  httpBefore(); //请求前的处理
  let promise = new Promise((resolve, reject) => {
    wx.request({
      url: DomainName+url,
      data: { ...data },
      method: method,
      header: {
        "content-type": contentType
      },
      success: (data) => {
        resolve(data);
      },
      fail: (err) => {
        reject(err)
        console.log(err);
      }
    });
  });
  return promise;
}

export default http;